//
//  StartExamViewController.m
//  Drivers
//
//  Created by Hunk on 10-11-1.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "StartExamViewController.h"
#import "WriteFile.h"
#import "RandomHelper.h"
#import <AudioToolbox/AudioToolbox.h>
#import "ReviewViewController.h"
#import "CoverViewController.h"
#import "ReviewViewController.h"

#define COUNT_TOTALQUESTION (100) // 如有100题,这里需要填写100

#define COUNT_TOTALMULTIPLECHOICE (346) // 真实选择题题目数量(Plist文件Value值)

#define COUNT_TOTALJUDGEMENT (290) // 真实判断题目数量(Plist文件Value值)

#define COUNT_MULTIPLECHOICE (60) // 需要选择题目数量

#define COUNT_JUDGEMENT (40) // 需要判断题目数量

#define TITLE_ALERT_SUBMITORNOT @"您已经做完了本次考试的所有题目,是否交卷?"

#define TITLE_ALERT_HASBEENADDED @"此题已经添加过,请勿重复添加"

#define TITLE_ALERT_FIRSTQUESTION @"这已经是第一题了"

#define TITLE_ALERT_SUBMITWITHOUTDOING @"您一道题都没做,就交卷啊?!!"

#define TITLE_ALERT_SUBMIT @"确认交卷?"

#define FILE_STRENGTHENINGMEMORY @"StrengtheningMemory.sg" // 记录文件路径的文件

#define PLIST_STRENGTHENINGMEMORY @"StrengtheningMemory.plist" // 记录强化记忆题目

#define FILE_WRONGQUESTION @"WrongQuestion.sg"

#define PLIST_WRONGQUESTION @"WrongQuestion.plist"

#define DURATION_VIEWFLIP (0.8f)


@interface StartExamViewController (Private)

- (void)getQuestion:(int)nQuestionNumber;

- (void)viewFlip:(NSString*)flipMode;

- (int)getScore;

- (void)answerButtonHandle:(NSString*)strAnswer;

- (void)recordWrongQuestion:(NSString*)strAnswer nCurQuestionNumber:(int)nCurQuestion;

- (void)showPrevChooseAnswer:(int)nQuestionNumber;

- (void)startTest;

- (void)addLabelText:(UILabel*)label labelText:(NSString*)labelText;

- (void)showAlert:(NSString*)alertTitle cancel:(NSString*)cancelButtonTitle other:(NSString*)otherButtonTitle;

@end


@implementation StartExamViewController

@synthesize m_pAButton;
@synthesize m_pBButton;
@synthesize m_pCButton;
@synthesize m_pDButton;
@synthesize m_pPrevButon;
@synthesize m_pNextButon;
@synthesize m_pResultButton;
@synthesize m_pStrengtheningMemoryButton;
@synthesize m_pImageView;
@synthesize m_pPrevChoose;


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad 
{
	[super viewDidLoad];
	
    UIImage *image = [UIImage imageNamed:@"cell_background.png"];
    [_bgImageView setImage:[image stretchableImageWithLeftCapWidth:5 topCapHeight:5]];
    
    [UIView viewLayerCorner:m_pAButton];
    [UIView viewLayerCorner:m_pBButton];
    [UIView viewLayerCorner:m_pCButton];
    [UIView viewLayerCorner:m_pDButton];
    [UIView viewLayerCorner:m_pPrevButon];
    [UIView viewLayerCorner:m_pNextButon];
    [UIView viewLayerCorner:m_pStrengtheningMemoryButton];
    
	// Add right bar button item
	UIBarButtonItem* rightBarButtonItem = [[[UIBarButtonItem alloc] initWithTitle:@"交卷"
																			style:UIBarButtonItemStyleBordered
																		   target:self
																		   action:@selector(rightBarButtonItemHandle:)] autorelease];
	self.navigationItem.rightBarButtonItem = rightBarButtonItem;
	
	// Init data
	m_nCurQuestionNumber = 0;
	m_arrayOfStandardAnswer = [[NSMutableArray alloc] init];
	m_arrayOfTestingAnswer  = [[NSMutableArray alloc] init];
	m_arrayOfStrengtheningMemory = [[NSMutableArray alloc] init];
	m_arrayOfWrongQuestion = [[NSMutableArray alloc] init];
	m_arrayOfExamination = [[NSMutableArray alloc] init];
	
	// Init Question label
	m_pQuestionLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, 300, 500)];
	m_pQuestionLabel.numberOfLines = 0;
	m_pQuestionLabel.backgroundColor = [UIColor clearColor];	
	m_pQuestionLabel.textColor = [UIColor blackColor];
	m_pQuestionLabel.font = [UIFont fontWithName:@"AmericanTypewriter" size:18];
	m_pQuestionLabel.textAlignment = UITextAlignmentLeft;
	[self addLabelText:m_pQuestionLabel labelText:nil];
	[self.view addSubview:m_pQuestionLabel];
	
	
	
	// Set navigation title
	self.navigationController.visibleViewController.title = @"共100题,第1题";
	
	
	// Get plist file path
	NSString* strExamPath = [[NSBundle mainBundle] pathForResource:@"Exam" ofType:@"plist"];
	
	// Get root dictionary
	m_dicOfRoot = [[NSDictionary alloc] initWithContentsOfFile:strExamPath];
	
	// Get MultipleChoice question array
	m_arrayOfMultipleChoice = [m_dicOfRoot objectForKey:@"Exam_001"];
	
	// 输出题目一样的选择题题号
	/*
	for(int j = 0; j < [m_arrayOfMultipleChoice count]; j++)
	{
		NSString* str1 = [[m_arrayOfMultipleChoice objectAtIndex:j] objectAtIndex:0];
		
		for(int i = 0; i < [m_arrayOfMultipleChoice count]; i++)
		{
			NSString* str2 = [[m_arrayOfMultipleChoice objectAtIndex:i] objectAtIndex:0];
			if([str1 isEqualToString:str2])
			{
				if(j == i)
				{}
				else
				{
					if([[m_arrayOfMultipleChoice objectAtIndex:i] isEqualToArray:[m_arrayOfMultipleChoice objectAtIndex:j]])
					{
						NSLog(@"选择题:j = %d --------- i = %d\n", j, i);
					}
				}
			}
		}
	}
	*/
	
	// Get Judgement question array
	m_arrayOfJudgement = [m_dicOfRoot objectForKey:@"Exam_002"];
	
	
//	for(int i = 0; i < [m_arrayOfMultipleChoice count]; i++)
//	{
//		if([[[m_arrayOfMultipleChoice objectAtIndex:i] objectAtIndex:1] isEqualToString:@"直行和左转弯车道"])
//		{
//			NSLog(@"i == %d\n", i);
//		}
//	}
	
	
	
//	for(int j = 0; j < [m_arrayOfJudgement count]; j++)
//	{
//		NSString* str1 = [[m_arrayOfJudgement objectAtIndex:j] objectAtIndex:0];
//		NSLog(@"j == %d, str1 = %@\n", j, str1);
////		NSString* str2 = @"";
////		if([str1 isEqualToString:str2])
////		{
////			NSLog(@"j == %d\n", j);
////		}
//	}
	

	// 输出一样题目的判断题题号
	/*
	for(int j = 0; j < [m_arrayOfJudgement count]; j++)
	{
		NSString* str1 = [[m_arrayOfJudgement objectAtIndex:j] objectAtIndex:0];
		
		for(int i = 0; i < [m_arrayOfJudgement count]; i++)
		{
			NSString* str2 = [[m_arrayOfJudgement objectAtIndex:i] objectAtIndex:0];
			if([str1 isEqualToString:str2])
			{
				if(j == i)
				{}
				else
				{
					if([[m_arrayOfJudgement objectAtIndex:i] isEqualToArray:[m_arrayOfJudgement objectAtIndex:j]])
					{
						NSLog(@"判断题:j = %d --------- i = %d\n", j, i);
					}
				}
			}
		}
	}
	*/
	
	
	// Start test
	[self startTest];
}


#pragma mark -
#pragma mark Start test
- (void)startTest
{	
	// Init data
	m_nCurQuestionNumber = 0;
	[m_arrayOfStandardAnswer removeAllObjects];
	[m_arrayOfTestingAnswer removeAllObjects];
	[m_arrayOfStrengtheningMemory removeAllObjects];
	[m_arrayOfWrongQuestion removeAllObjects];
	[m_arrayOfExamination removeAllObjects];
	m_pPrevChoose.hidden = YES;
	
	// Multiple choice number
	NSArray* arrayOfMultipleChoiceNumber = [RandomHelper getRandomArray:0 max:(COUNT_TOTALMULTIPLECHOICE - 1) need:COUNT_MULTIPLECHOICE];
	// Judgement number
	NSArray* arrayOfJudgementNumber      = [RandomHelper getRandomArray:0 max:(COUNT_TOTALJUDGEMENT - 1) need:COUNT_JUDGEMENT];
	
	// Get Exam_001 array
	for(int i = 0; i < [arrayOfMultipleChoiceNumber count]; i++)
	{
		[m_arrayOfExamination addObject:[m_arrayOfMultipleChoice objectAtIndex:[[arrayOfMultipleChoiceNumber objectAtIndex:i] intValue]]];
	}
	
	for(int i = 0; i < [arrayOfJudgementNumber count]; i++)
	{
		[m_arrayOfExamination addObject:[m_arrayOfJudgement objectAtIndex:[[arrayOfJudgementNumber objectAtIndex:i] intValue]]];
	}	
	
	// Get question
	[self getQuestion:0];	
}

#pragma mark -
#pragma mark Prev page
- (IBAction)prevPage:(id)sender
{
	m_nCurQuestionNumber--;
	if(m_nCurQuestionNumber < 0)
	{
		m_nCurQuestionNumber++;
		
		// Show alert
		[self showAlert:TITLE_ALERT_FIRSTQUESTION cancel:@"哦,知道了" other:nil];

		return;
	}
	
	// View flip
	[self viewFlip:@"Down"];	
	
	// Get question
	[self getQuestion:m_nCurQuestionNumber];
	
	// Show prev choose answer
	[self showPrevChooseAnswer:m_nCurQuestionNumber];
}

#pragma mark -
#pragma mark Next page
- (IBAction)nextPage:(id)sender
{	
	// Add "没选" object
	if([m_arrayOfTestingAnswer count] < (m_nCurQuestionNumber + 1))
	{
		[m_arrayOfTestingAnswer addObject:@"没选"];
		
		// Record wrong question
		[self recordWrongQuestion:@"没选" nCurQuestionNumber:m_nCurQuestionNumber];
	}
	
	
	m_nCurQuestionNumber++;
	if(m_nCurQuestionNumber > (COUNT_TOTALQUESTION - 1))
	{
		m_nCurQuestionNumber--;
		
		// Show alert
		[self showAlert:TITLE_ALERT_SUBMITORNOT cancel:@"否" other:@"是"];

		return;
	}
	
	// View flip
	[self viewFlip:@"Up"];
	
	// Get question
	[self getQuestion:m_nCurQuestionNumber];
	
	// Show prev choose answer
	[self showPrevChooseAnswer:m_nCurQuestionNumber];
}

#pragma mark -
#pragma mark Get question
- (void)getQuestion:(int)nQuestionNumber
{
	if(nQuestionNumber > (COUNT_TOTALQUESTION - 1))
	{
		// Show alert
		[self showAlert:TITLE_ALERT_SUBMITORNOT cancel:@"否" other:@"是"];

		return;
	}
	
	// Set title
	[self.navigationController.visibleViewController setTitle:[NSString stringWithFormat:@"共%d题,第%d题", [m_arrayOfExamination count], (nQuestionNumber + 1)]];
	
	// Get the first question from the Exam_001 array
	NSArray* arrayOfQuestion = [m_arrayOfExamination objectAtIndex:nQuestionNumber];
//	NSArray* arrayOfQuestion = [m_arrayOfMultipleChoice objectAtIndex:19];
	
//	NSLog(@"\n\n");
//	for(int i = 0; i < [arrayOfQuestion count]; i++)
//	{
//		NSLog(@"QUESTION:%@\n", [arrayOfQuestion objectAtIndex:i]);
//	}
//	NSLog(@"\n\n");
	
	// Add label text
	[self addLabelText:m_pQuestionLabel labelText:[arrayOfQuestion objectAtIndex:0]];
	
	if(nQuestionNumber >= 0 && nQuestionNumber < COUNT_MULTIPLECHOICE)
	{
		m_pAButton.hidden = NO;
		m_pBButton.hidden = NO;
		m_pCButton.hidden = NO;
		m_pDButton.hidden = NO;
		
		[m_pAButton setTitle:[@"A:" stringByAppendingString:[arrayOfQuestion objectAtIndex:1]] forState:UIControlStateNormal];
		[m_pBButton setTitle:[@"B:" stringByAppendingString:[arrayOfQuestion objectAtIndex:2]] forState:UIControlStateNormal];
		[m_pCButton setTitle:[@"C:" stringByAppendingString:[arrayOfQuestion objectAtIndex:3]] forState:UIControlStateNormal];
		[m_pDButton setTitle:[@"D:" stringByAppendingString:[arrayOfQuestion objectAtIndex:4]] forState:UIControlStateNormal];
		
		// Cache answer
		[m_arrayOfStandardAnswer insertObject:[arrayOfQuestion objectAtIndex:5] atIndex:nQuestionNumber];
		
		m_pImageView.alpha = 0.f;
		
		if(7 == [arrayOfQuestion count])
		{
			m_pImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[arrayOfQuestion objectAtIndex:6]]];
			
			float fWidth = m_pImageView.frame.size.width;
			float fHeight = m_pImageView.frame.size.height;
			m_pImageView.alpha = 1.f;
			
			[m_pImageView setFrame:CGRectMake((320 - fWidth)/2, m_pQuestionLabel.frame.size.height + 10 + 10, fWidth, fHeight)];
			[self.view addSubview:m_pImageView];
			[m_pImageView release];
		}
	}
	else
	{
		m_pAButton.hidden = YES;
		m_pBButton.hidden = YES;
		m_pCButton.hidden = NO;
		m_pDButton.hidden = NO;
		
		[m_pCButton setTitle:@"正确" forState:UIControlStateNormal];
		[m_pDButton setTitle:@"错误" forState:UIControlStateNormal];
		
		// Cache answer
		[m_arrayOfStandardAnswer insertObject:[arrayOfQuestion objectAtIndex:1] atIndex:nQuestionNumber];
		
		m_pImageView.alpha = 0.f;
		
		if(3 == [arrayOfQuestion count])
		{
			m_pImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:[arrayOfQuestion objectAtIndex:2]]];
			
			float fWidth = m_pImageView.frame.size.width;
			float fHeight = m_pImageView.frame.size.height;
			m_pImageView.alpha = 1.f;
			
			[m_pImageView setFrame:CGRectMake((320 - fWidth)/2, m_pQuestionLabel.frame.size.height + 50, fWidth, fHeight)];
			[self.view addSubview:m_pImageView];
			[m_pImageView release];
		}
	}
}

#pragma mark -
#pragma mark Answer A button
- (IBAction)answerAButton:(id)sender
{
	[self answerButtonHandle:@"A"];
}

#pragma mark -
#pragma mark Answer B button
- (IBAction)answerBButton:(id)sender
{
	[self answerButtonHandle:@"B"];
}

#pragma mark -
#pragma mark Answer C button
- (IBAction)answerCButton:(id)sender
{
	[self answerButtonHandle:@"C"];
}

#pragma mark -
#pragma mark Answer D button
- (IBAction)answerDButton:(id)sender
{
	[self answerButtonHandle:@"D"];
}

#pragma mark -
#pragma mark Get score
- (int)getScore
{
	int nScore = 0;
	
	for(int i = 0; i < [m_arrayOfTestingAnswer count]; i++)
	{
		if([[m_arrayOfTestingAnswer objectAtIndex:i] isEqualToString:[m_arrayOfStandardAnswer objectAtIndex:i]])
		{
			nScore++;
		}
	}
	return nScore;
}

#pragma mark -
#pragma mark View flip
- (void)viewFlip:(NSString*)flipMode
{
	[UIView beginAnimations:@"View Flip" context:nil];
	[UIView setAnimationDuration:DURATION_VIEWFLIP];
	[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
	
	if([flipMode isEqualToString:@"Up"])
	{
		[UIView setAnimationTransition:UIViewAnimationTransitionCurlUp forView:self.view cache:YES];
	}
	else if([flipMode isEqualToString:@"Down"])
	{
		[UIView setAnimationTransition:UIViewAnimationTransitionCurlDown forView:self.view cache:YES];
	}
	[self viewWillAppear:YES];
	[UIView commitAnimations];
	
	// Play effect
	NSString* effectPath = [[NSBundle mainBundle] pathForResource:@"FlipPage" ofType:@"caf"];
	SystemSoundID soundID;
	AudioServicesCreateSystemSoundID((CFURLRef)[NSURL fileURLWithPath:effectPath], &soundID);
	AudioServicesPlaySystemSound(soundID);	
}

#pragma mark -
#pragma mark Answer button handle
- (void)answerButtonHandle:(NSString*)strAnswer
{
	// Record testing answer
	if([m_arrayOfTestingAnswer count] < (m_nCurQuestionNumber + 1))
	{
		[m_arrayOfTestingAnswer insertObject:strAnswer atIndex:m_nCurQuestionNumber];
	}
	else if([m_arrayOfTestingAnswer count] == (m_nCurQuestionNumber + 1))
	{
		[m_arrayOfTestingAnswer replaceObjectAtIndex:m_nCurQuestionNumber withObject:strAnswer];
	}
	else
	{
		[m_arrayOfTestingAnswer replaceObjectAtIndex:m_nCurQuestionNumber withObject:strAnswer];
	}
	
	// If you answer the question wrong, put it to m_arrayOfWrongQuestion
	if(![[m_arrayOfStandardAnswer objectAtIndex:m_nCurQuestionNumber] isEqualToString:strAnswer])
	{
		[self recordWrongQuestion:strAnswer nCurQuestionNumber:m_nCurQuestionNumber];
	}
	
	// Go to next question
	m_nCurQuestionNumber++;
	if(m_nCurQuestionNumber > (COUNT_TOTALQUESTION - 1))
	{
		m_nCurQuestionNumber--;
		
		// Show alert
		[self showAlert:TITLE_ALERT_SUBMITORNOT cancel:@"否" other:@"是"];

		return;
	}
	
	[self viewFlip:@"Up"];
	
	// Get question
	[self getQuestion:m_nCurQuestionNumber];
	
	// Show prev choose answer
	[self showPrevChooseAnswer:m_nCurQuestionNumber];
}

#pragma mark -
#pragma mark Strengthening memory
- (IBAction)strengtheningMemory:(id)sender
{	
	NSArray* arrayOfFilePath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask,YES);
    NSString* strFilePath = [[arrayOfFilePath objectAtIndex:0] stringByAppendingPathComponent:PLIST_STRENGTHENINGMEMORY];
	NSMutableArray* _tempArrayOfStrengtheningMemory = [[NSMutableArray alloc] initWithContentsOfFile:strFilePath];
	[m_arrayOfStrengtheningMemory removeAllObjects];
	[m_arrayOfStrengtheningMemory addObjectsFromArray:_tempArrayOfStrengtheningMemory];
	
	// One question
	NSMutableArray* arrayOfQuestion = [m_arrayOfExamination objectAtIndex:m_nCurQuestionNumber];
	
	if([m_arrayOfStrengtheningMemory count] <= 0)
	{		
		// Strengthening memory array
		[m_arrayOfStrengtheningMemory addObject:arrayOfQuestion];
		
		[m_arrayOfStrengtheningMemory writeToFile:strFilePath atomically:YES];
		
		// Write file name to file 
		WriteFile* writeFile = [[WriteFile alloc] init];
		[writeFile WriteString:strFilePath];
		[writeFile CloseFile:FILE_STRENGTHENINGMEMORY];
		[writeFile release];
	}
	else if([m_arrayOfStrengtheningMemory count] > 0)
	{
		for(int i = 0; i < [m_arrayOfStrengtheningMemory count]; i++)
		{
//			if([[[m_arrayOfStrengtheningMemory objectAtIndex:i] objectAtIndex:0] isEqualToString:[arrayOfQuestion objectAtIndex:0]])
            if([[m_arrayOfStrengtheningMemory objectAtIndex:i] isEqualToArray:arrayOfQuestion])
			{
				// Show alert
				[self showAlert:TITLE_ALERT_HASBEENADDED cancel:@"好的" other:nil];
			
				return;
			}
		}
		// Strengthening memory array
		[m_arrayOfStrengtheningMemory addObject:arrayOfQuestion];
		
		[m_arrayOfStrengtheningMemory writeToFile:strFilePath atomically:YES];
		
		// Write file name to file 
		WriteFile* writeFile = [[WriteFile alloc] init];
		[writeFile WriteString:strFilePath];
		[writeFile CloseFile:FILE_STRENGTHENINGMEMORY];
		[writeFile release];
	}	
}

#pragma mark -
#pragma mark Alert view delegate
- (void)alertView:(UIAlertView *)alertView clickedButtonAtIndex:(NSInteger)buttonIndex
{		
	if([alertView.title isEqualToString:TITLE_ALERT_SUBMITORNOT] || [alertView.title isEqualToString:TITLE_ALERT_SUBMIT])
	{
		// Exam again
		if(buttonIndex == 0)
		{}
		// Check wrong question
		else if(buttonIndex == 1)
		{
			NSString* strAlertTitle = [NSString stringWithFormat:@"本次考试成绩:%d分", [self getScore]];
			
			// Show alert
			[self showAlert:strAlertTitle cancel:@"再考一次" other:@"查看错题"];
		}

	}
	else if([alertView.title isEqualToString:TITLE_ALERT_HASBEENADDED])
	{}
	else if([alertView.title isEqualToString:TITLE_ALERT_FIRSTQUESTION])
	{}
	// Check wrong question(s)
	else if([alertView.title isEqualToString:[NSString stringWithFormat:@"本次考试成绩:%d分", [self getScore]]])
	{
		if(buttonIndex == 0)
		{
			[self startTest];
		}
		else
		{
			// Return to main menu
			[self.navigationController popViewControllerAnimated:YES];
		}
	}
	else if([alertView.title isEqualToString:TITLE_ALERT_SUBMITWITHOUTDOING])
	{
		if(buttonIndex == 0)
		{}
		else
		{
			NSString* strAlertTitle = [NSString stringWithFormat:@"本次考试成绩:%d分", [self getScore]];
			
			// Show alert
			[self showAlert:strAlertTitle cancel:@"再考一次" other:@"查看错题"];
		}
	}
}

#pragma mark -
#pragma mark Record wrong question
- (void)recordWrongQuestion:(NSString*)strAnswer nCurQuestionNumber:(int)nCurQuestionNumber
{
	// Get wrong question
	NSMutableArray* arrayOfWrongQuestion = [[NSMutableArray alloc] initWithArray:[m_arrayOfExamination objectAtIndex:nCurQuestionNumber]];
	

	if(![m_arrayOfWrongQuestion containsObject:arrayOfWrongQuestion])
	{
		// Add the testing answer
		[arrayOfWrongQuestion insertObject:strAnswer atIndex:[arrayOfWrongQuestion count]];
		
		[m_arrayOfWrongQuestion addObject:arrayOfWrongQuestion];
	}
	
	[arrayOfWrongQuestion release];
	arrayOfWrongQuestion = nil;

	NSArray* arrayOfPath = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
	NSString* strFileName = [[arrayOfPath objectAtIndex:0] stringByAppendingPathComponent:PLIST_WRONGQUESTION];
	[m_arrayOfWrongQuestion writeToFile:strFileName atomically:YES];

	// Write file name to file 
	WriteFile* writeFile = [[WriteFile alloc] init];
	[writeFile WriteString:strFileName];
	[writeFile CloseFile:FILE_WRONGQUESTION];
	[writeFile release];
	
//	NSMutableArray* _arrayOfStrengtheningMemory = [[NSMutableArray alloc] initWithContentsOfFile:strFileName];	
//	
//	NSLog(@"%d\n",[_arrayOfStrengtheningMemory count]);
}

#pragma mark -
#pragma mark Show PrevChoose answer
- (void)showPrevChooseAnswer:(int)nQuestionNumber
{
	m_pPrevChoose.hidden = YES;
	if([m_arrayOfTestingAnswer count] != 0 && (([m_arrayOfTestingAnswer count] - 1) >= nQuestionNumber) && nil != [m_arrayOfTestingAnswer objectAtIndex:nQuestionNumber])
	{
		m_pPrevChoose.hidden = NO;
		m_pPrevChoose.numberOfLines = 5;
		NSString* strTestingAnswer;
		if(nQuestionNumber < COUNT_MULTIPLECHOICE)
		{
			strTestingAnswer = [m_arrayOfTestingAnswer objectAtIndex:nQuestionNumber];
		}
		else
		{
			strTestingAnswer = [m_arrayOfTestingAnswer objectAtIndex:nQuestionNumber];
			if([strTestingAnswer isEqualToString:@"C"])
			{
				strTestingAnswer = @"正确";
			}
			else if([strTestingAnswer isEqualToString:@"D"])
			{
				strTestingAnswer = @"错误";
			}
			else if([strTestingAnswer isEqualToString:@"没选"])
			{
				strTestingAnswer = @"没选";
			}
		}
		[m_pPrevChoose setText:[@"上\n次\n所\n选\n" stringByAppendingString:strTestingAnswer]];
	}
}

#pragma mark -
#pragma mark - Add label text
- (void)addLabelText:(UILabel*)label labelText:(NSString*)labelText
{
	label.text = labelText;
	
	CGSize size = [label.text sizeWithFont:label.font constrainedToSize:CGSizeMake(300, 500) lineBreakMode:UILineBreakModeCharacterWrap];
	
	label.frame = CGRectMake(15, 10, size.width, size.height);
}

#pragma mark -
#pragma mark Right bar button item handle
- (void)rightBarButtonItemHandle:(id)sender
{
	NSString* strAlertTitle;
	
	if(0 == [m_arrayOfTestingAnswer count])
	{
		strAlertTitle = [NSString stringWithFormat:TITLE_ALERT_SUBMITWITHOUTDOING];
	}
	else
	{
		strAlertTitle = [NSString stringWithFormat:TITLE_ALERT_SUBMIT];
	}
	
	// Alert
	[self showAlert:strAlertTitle cancel:@"取消" other:@"确认"];
}

#pragma mark -
#pragma mark Show alert
- (void)showAlert:(NSString*)alertTitle cancel:(NSString*)cancelButtonTitle other:(NSString*)otherButtonTitle
{
	UIAlertView* alertView = [[UIAlertView alloc] initWithTitle:alertTitle
														message:nil
													   delegate:self 
											  cancelButtonTitle:cancelButtonTitle 
											  otherButtonTitles:otherButtonTitle, nil];
	[alertView show];
	[alertView release];
}

#pragma mark -
// Override to allow orientations other than the default portrait orientation.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

- (void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

- (void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}


- (void)dealloc 
{
	[m_dicOfRoot release];
	[m_arrayOfStandardAnswer release];
	[m_arrayOfTestingAnswer release];
	[m_arrayOfStrengtheningMemory release];
	[m_arrayOfWrongQuestion release];
	[m_arrayOfExamination release];
	
    [super dealloc];
}


@end
